package simpleftp.client.control;

import simpleftp.client.gui.FTPClientWindow;

public final class Downloader implements Runnable
{
    private SimpleFTP client;
    private String server;
    private String port;
    private FTPClientWindow window;
    private String filePath;
    private String fileName;
    private String user;
    private String pass;
    
    public Downloader(FTPClientWindow window, String filePath, String fileName, String server, String port, String user, String pass) {
        this.window = window;
        this.filePath = filePath;
        this.server = server;
        this.port = port;
        this.user = user;
        this.pass = pass;
        this.fileName = fileName;
        this.client = new SimpleFTP();
    }
    
    @Override
    public void run() {
        System.out.println("DOWNLOAD starting for " + filePath);
        try {
            System.out.println("In downloader.java filePath & Name : "+filePath+" - "+fileName);
            client.connect(server, Integer.parseInt(port), user, pass);
            
            // On doit voir si le telechargement s effectue mais je n ai pas trouve l astuce.
            boolean result = true;
            
            if (result) {
                    window.console.append("\nSuccessfully downloaded file "
                                    + filePath);
                    System.out.println("\nSuccessfully downloaded file "
                                    + filePath);

            } else {
                    window.console.append("\nFailed downloaded file " + filePath);
                    System.out.println("\nFailed downloaded file "
                                    + filePath);
            }
        } catch (Exception ex) {
        	System.out.println(ex.getStackTrace());
        }
    }
}
